package com.example.comment.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.comment.dao.ApCommentMapper;
import com.example.comment.pojo.ApComment;
import com.example.comment.pojo.ApCommentDto;
import com.example.comment.service.ApCommentService;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.user.pojos.ApUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class ApCommentServiceImpl implements ApCommentService {
    @Autowired
    private ApCommentMapper apCommentMapper;
    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    public ResponseResult addComment(ApCommentDto apCommentDto) {
        if (apCommentDto==null || apCommentDto.getUserId()==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_REQUIRE);
        }
        Boolean userReturn = redisTemplate.hasKey(apCommentDto.getUserId());
        if (!userReturn){
            return ResponseResult.errorResult(AppHttpCodeEnum.LONGIN_BLOCK);
        }
        String apUser1 = (String) redisTemplate.opsForValue().get(apCommentDto.getUserId());
        ApUser apUser = JSON.parseObject(apUser1, ApUser.class);
        log.info("用户为:{}",apUser);
        if (apUser==null){
            return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
        }
        ApCommentDto apCommentDto1 = new ApCommentDto();
        apCommentDto1.setContent(apCommentDto.getContent());

        return null;
    }
}
